package com.atguigu.spzx.manager.demo;

import com.alibaba.excel.EasyExcel;
import com.atguigu.spzx.manager.listener.ExcelListener;
import com.atguigu.spzx.model.vo.product.CategoryExcelVo;
import org.apache.commons.lang3.RandomUtils;

import java.util.ArrayList;

/**
 * ClassName: EasyExcelTest
 * Package: com.atguigu.spzx.manager.demo
 * Description:
 *
 * @Author 刘强
 * @Create 2024/7/4 17:41
 * @Version 1.0
 */
public class EasyExcelTest {
    public static void main(String[] args) {
//        easyExcelRead();
        easyExcelWrite();
    }


    private static void easyExcelWrite() {
        String excelFilePath = "D:\\01.xlsx";
        EasyExcel.write(excelFilePath).sheet("小刘分类").head(CategoryExcelVo.class).doWrite(()->{
            ArrayList<CategoryExcelVo> categoryExcelVos = new ArrayList<>();
            for (int i = 0; i <10; i++) {
                CategoryExcelVo categoryExcelVo = new CategoryExcelVo(Long.parseLong((i + 1) + ""), "分类" + (i + 1), "", RandomUtils.nextLong(0, 10),
                        1, 1);
                categoryExcelVos.add(categoryExcelVo);
            }
            return categoryExcelVos;
        });
        System.out.println("写出完毕");
    }

    private static void easyExcelRead() {
        String excelFilePath = "D:\\01.xlsx";
        ExcelListener<CategoryExcelVo> excelListener = new ExcelListener<>();
        EasyExcel.read(excelFilePath,excelListener).sheet().doRead();
    }
}
